<?php
/* Home controller 
** thaodx@gmail.com
*/
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Detail extends CI_Controller {
	public function index($id = 0)
	{
		$id = intval($id);
		$data = array();
		if($id > 0){
			$this->load->model('Post_model', 'postModel');
			$this->load->helper(array('datetime', 'permalink', 'social', 'image'));
			$postDetail = $this->postModel->getPostDetail($id);
			$this->layout->title(strip_tags($postDetail[0]->post_title)); // Set page title
			$this->layout->desc(strip_tags($postDetail[0]->post_title)); // Set meta description
			$data['permalink'] = permalink(array('text' => $postDetail[0]->post_title, 'id' => $postDetail[0]->id));
			// meta tags
			$this->layout->meta('<meta property="og:image" content="'.getThumbnail('460x460', $postDetail[0]->post_image).'"/>');
			$this->layout->meta('<meta property="og:title" content="'.str_replace('"', '', $postDetail[0]->post_title).'"/>');
			$this->layout->meta('<meta property="og:url" content="'.$data['permalink'].'"/>');
			$data['detail'] = $postDetail[0];

			if(!empty($data['detail'])){
				// older post
				$blockdata['olderPost'] = $this->postModel->getOlderPost($data['detail']->id);
				// right block, next, prev control
				$blockdata['viewmore'] = $this->postModel->navigationPost($id);
				$blockdata['detail'] = $data['detail'];
				$sidebar = $this->layout->renderBlock('block/detail-post-control', $blockdata);
				$this->layout->sidebar($sidebar);
			}
			// update view
			$this->postModel->updatePostView($id);
			$this->layout->view('detail_index', $data);
		}
	}
}